import { Dispatch } from 'redux';
import type { IStateType, ILiveBroadData } from './index.d';

export const MODULE_NAME: string = 'LiveBroadRoom';

export const types = {
  LIVE_BROAD_DATA: `${MODULE_NAME}/LIVE_BROAD_DATA`, // 视频数据
}

export default (state: IStateType = {
  liveBroadData: null
}, action: any) => {
  switch (action.type) {
    case types.LIVE_BROAD_DATA:
      return Object.assign({}, state, {
        liveBroadData: action.data
      })
    default: return state
  }
}

/**
 * 获取列表数据
*/
export const getDataById = (id: string) => {
  return async (dispatch: Dispatch): Promise<void> => {
    try {
      const data: ILiveBroadData[] = [{
        id: '10003',
        url: [
          'rtsp://47.104.198.202:554/openUrl/sFQqxQk',
          'rtmp://47.104.198.202:1935/live/openUrl/zPFGpmE'
        ]
      }]

      dispatch({
        type: types.LIVE_BROAD_DATA,
        data: data.find(item => item.id === id)
      })
    } catch { }
  }
}
